package com.samp.base.math;

public class CalAngle {
    /**
     *
     * 三个点的x,y,z的坐标。
     * @return
     */
    private static float calAngle(float x1, float x2, float y1, float y2, float z1, float z2){
        float t =(y1-x1)*(z1-x1)+(y2-x2)*(z2-x2);
        float result =(int)(180*Math.acos(
                                 t/Math.sqrt
                                 ((Math.abs((y1-x1)*(y1-x1))+Math.abs((y2-x2)*(y2-x2)))
                         *(Math.abs((z1-x1)*(z1-x1))+Math.abs((z2-x2)*(z2-x2)))
                         ))
                         /Math.PI);
        return result;
    }

    /**
     * 计算两个点的水平夹角
     *
     */
    public static float calHorizontalAngle(float x1, float x2, float y1, float y2){
        return calAngle(x1,x2,y1,y2,x1,y2);
    }

    public static void main(String[] args) {
        int x1=255;
        int x2=145;
        int y1=211;
        int y2=147;
        int z1=271;
        int z2=182;
        float result = calAngle(x1, x2, y1, y2, z1, z2);
        System.out.println("夹角为："+result+"度");
        System.out.println("夹角为："+calHorizontalAngle(1,1,0,0)+"度");
    }
}
